package com.yida.service;

import java.beans.Transient;
import java.sql.Timestamp;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yida.bean.blogUser;
import com.yida.bean.blogUserThird;
import com.yida.dao.loginMapper;

@Service
public class serverLoginImpl implements serverLogin{

	
	@Autowired
	loginMapper loginMapper;
	
	
	@Override
	public Integer ThirdByUnique(String openid) {
		// TODO Auto-generated method stub
		return loginMapper.ThirdByUnique(openid);
	}


	@Override
	@Transactional
	public blogUser insertThirdUserAndUser(String third_unique_acount, String type,String nickname,String sex,String imgUrl) {
		// TODO Auto-generated method stub
		  blogUser blogUser =  new blogUser();
		  blogUser.setNickname(nickname);
		  blogUser.setImgUrl(imgUrl);	
		  blogUser.setSex(sex);
		  
		  Date date = new Date();
		  blogUser.setCreate_date(new java.sql.Date(date.getTime()));
		  blogUser.setSource_from("QQ");
		   
		  Integer insertUser= loginMapper.insertUser(blogUser);
		  System.out.println(blogUser.getId());
		
		
		blogUserThird blogUserThird = new blogUserThird();
		blogUserThird.setThird_unique_acount(third_unique_acount);
		blogUserThird.setType(type);	
		blogUserThird.setBlogUserId(blogUser.getId());
		
		//设置时间
		Date date2 = new Date();
	    blogUserThird.setCreate_date(new java.sql.Date(date2.getTime()));
		
		  Integer insertThird = loginMapper.insertThirdUser(blogUserThird);
		

		  if (insertThird>0 && insertUser >0) {
			return blogUser;
		  }else {
			return null;
		  }
		  
	
	}


	@Override
	public blogUser blogUserByOpenId(String openid) {
		
		// TODO Auto-generated method stub
		return loginMapper.blogUserByOpenId(openid);
	}

}
